package com.gxa.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;
import java.util.List;

@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {

    @Bean
    public Docket createRestApi001() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("系统用户模块")
            .apiInfo(apiInfo001())
            .select()
            //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
            //包下的类，才生成接口文档 com.gxa.modules.sys.controller
            .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.sys"))
            .paths(PathSelectors.any())
            .build()
            .securitySchemes(security());
    }

    private ApiInfo apiInfo001() {
        return new ApiInfoBuilder()
            .title("hrs项目")
            .description("系统用户模块在线文档")
            .termsOfServiceUrl("https://www.baidu.com")
            .version("3.0.0")
            .build();
    }

    @Bean
    public Docket createRestApi002() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("小程序用户登录")
                .apiInfo(apiInfo002())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.app.login"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo002() {
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("系统用户模块在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }

    @Bean
    public Docket createRestApi003() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("小程序--医院服务")
                .apiInfo(apiInfo003())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.app.hospital"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo003() {
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("小程序--医院服务在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }

    @Bean
    public Docket createRestApi004() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("小程序--住院服务")
                .apiInfo(apiInfo004())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller  com.gxa.modules.app.hospitalization
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.app.hospitalization"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo004() {
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("小程序--住院服务在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }

    @Bean
    public Docket createRestApi005() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("小程序--轮播图")
                .apiInfo(apiInfo005())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.app.carousel"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo005() {
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("小程序--轮播图")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }
    @Bean
    public Docket createRestApi006() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("小程序--门诊服务")
                .apiInfo(apiInfo006())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller  com.gxa.modules.app.outpatient
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.app.outpatient"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo006() {
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("小程序--门诊服务在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }

    @Bean
    public Docket createRestApi007() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("后台--费用管理")
                .apiInfo(apiInfo007())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.pc.fee.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo007() {
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("后台--费用管理在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }

    @Bean
    public Docket createRestApi008() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("后台--医院信息")
                .apiInfo(apiInfo008())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.pc.hospital"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo008() {
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("后台--医院信息在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }

    @Bean
    public Docket createRestApi009() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("后台--预约管理")
                .apiInfo(apiInfo009())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.pc.order.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo009(){
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("后台--预约管理在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }

    @Bean
    public Docket createRestApi010() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("后台--系统（首页、系统设置）")
                .apiInfo(apiInfo010())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.pc.sys"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo010(){
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("后台--预约管理在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }
    @Bean
    public Docket createRestApi011() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("小程序--微信、短信登录")
                .apiInfo(apiInfo011())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.app.login.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo011(){
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("后台--预约管理在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }
    @Bean
    public Docket createRestApi012() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("文件上传")
                .apiInfo(apiInfo012())
                .select()
                //加了ApiOperation注解的类，才生成接口文档
//            .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类，才生成接口文档 com.gxa.modules.sys.controller
                .apis(RequestHandlerSelectors.basePackage("com.gxa.modules.oss.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo012(){
        return new ApiInfoBuilder()
                .title("hrs项目")
                .description("后台--预约管理在线文档")
                .termsOfServiceUrl("https://www.baidu.com")
                .version("3.0.0")
                .build();
    }



    private List<ApiKey> security() {
        List<ApiKey> keys = new ArrayList<>();
        ApiKey apiKey = new ApiKey("token", "token", "header");
        keys.add(apiKey);
        return keys;
    }

}